import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-05-20
 * Time: 16:46
 */
public class test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int T = in.nextInt();
        for(int k=0;k<T;k++){
            int n = in.nextInt();
            int m = in.nextInt();
            int[][] area = new int[n][m];
            for(int p=0;p<n;p++){
                for(int q=0;q<m;q++){
                    area[p][q] = in.nextInt();
                }
            }
            boolean[][] visited = new boolean[n][m];
            int count = 0;
            int max = 0;
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    // 没有访问过并且有僵尸
                    if(area[i][j]>0 && !visited[i][j]){
                        count++;
                        // 僵尸浪潮僵尸数量
                        int current = dfs(area,visited,i,j,n,m);
                        max = Math.max(max,current);
                    }
                }
            }
            System.out.print(count);
            System.out.print(" ");
            System.out.print(max);
            System.out.println();
        }
    }


    public static int dfs(int[][]area,boolean[][] visited,int i,int j,int n,int m){
        if(i<0 || i>=n || j<0 || j>=m || visited[i][j] || area[i][j]==0){
            return 0;
        }else{
            visited[i][j] = true;
            int num = area[i][j];
            num+=dfs(area,visited,i-1,j,n,m);
            num+=dfs(area,visited,i+1,j,n,m);
            num+=dfs(area,visited,i,j-1,n,m);
            num+=dfs(area,visited,i,j+1,n,m);
            return num;
        }
    }
}
